library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity BarrelShifter is
  
  port (
    A   : in  std_logic_vector(31 downto 0);
    B   : in  std_logic_vector(31 downto 0);
    O_R   : out std_logic_vector(31 downto 0);
    O_L   : out std_logic_vector(31 downto 0));
end BarrelShifter;


architecture arch of BarrelShifter is

begin  -- arch

  process (A, B)
    variable templ : std_logic_vector(31 downto 0);
    variable tempr : std_logic_vector(31 downto 0);
  begin  -- process
    templ := A;
    tempr := A;
    for i in 4 downto 0 loop
      if(B(i) = '1') then        
          tempr := (31 downto 32-2**i  => '0') & (tempr(31 downto 2**i));
          templ := (templ(31 - 2**i downto 0)) & (2**i - 1 downto 0 => '0'); 
      end if;
    end loop;  -- i
    O_L <= templ;
    O_R <= tempr;
  end process;

end arch;
